{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名    马梓城\n",
    "+ 学号    0165265"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "佩戴上一克拉的梦想\n",
      "我的勇敢充满电量\n",
      "昂首到达每一个地方\n",
      "这世界的太阳\n",
      "因为自信才把我照亮\n",
      "这舞台的中央\n",
      "有我才闪亮\n",
      "有我才能发着光\n",
      "\n",
      "跟着我左手右手\n",
      "一个慢动作\n",
      "右手左手 慢动作重播\n",
      "这首歌给你快乐\n",
      "你有没有爱上我\n",
      "跟着我鼻子眼睛\n",
      "动一动耳朵\n",
      "装乖耍帅 换不停风格\n",
      "青春有太多未知的猜测\n",
      "成长的烦恼算什么\n",
      "\n",
      "这世界的太阳\n",
      "因为自信才把我照亮\n",
      "这舞台的中央\n",
      "有我才闪亮\n",
      "有我才能发着光\n",
      "\n",
      "跟着我左手右手\n",
      "一个慢动作\n",
      "右手左手 慢动作重播\n",
      "这首歌给你快乐\n",
      "你有没有爱上我\n",
      "跟着我鼻子眼睛\n",
      "动一动耳朵\n",
      "装乖耍帅 换不停风格\n",
      "青春有太多未知的猜测\n",
      "成长的烦恼算什么\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('佩戴上一克拉的梦想\\n'\n",
    "    '我的勇敢充满电量\\n'\n",
    "    '昂首到达每一个地方\\n'\n",
    "    '这世界的太阳\\n'\n",
    "    '因为自信才把我照亮\\n'\n",
    "    '这舞台的中央\\n'\n",
    "    '有我才闪亮\\n'\n",
    "    '有我才能发着光\\n')\n",
    "def fuge():\n",
    "    print('跟着我左手右手\\n'\n",
    "     '一个慢动作\\n'\n",
    "     '右手左手 慢动作重播\\n'\n",
    "     '这首歌给你快乐\\n'\n",
    "     '你有没有爱上我\\n'\n",
    "     '跟着我鼻子眼睛\\n'\n",
    "     '动一动耳朵\\n'\n",
    "     '装乖耍帅 换不停风格\\n'\n",
    "     '青春有太多未知的猜测\\n'\n",
    "     '成长的烦恼算什么\\n')\n",
    "fuge()\n",
    "print('这世界的太阳\\n'\n",
    "     '因为自信才把我照亮\\n'\n",
    "     '这舞台的中央\\n'\n",
    "     '有我才闪亮\\n'\n",
    "     '有我才能发着光\\n')\n",
    "fuge()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "共有12个数值\n",
      "均值为35.25\n",
      "样本方差为1182.19\n",
      "\n",
      "\n",
      "共有14个数值\n",
      "均值为30.07\n",
      "样本方差为36.49\n"
     ]
    }
   ],
   "source": [
    "def function(*number):\n",
    "    mean=0\n",
    "    var=0\n",
    "    var_sum=0\n",
    "    i=0\n",
    "    sum=0\n",
    "    for value in number:\n",
    "        sum=sum+value\n",
    "        i=i+1\n",
    "    mean=sum/i\n",
    "    print('共有%s个数值' %i)\n",
    "    print('均值为%.2f' %mean)\n",
    "    for value in number:\n",
    "        var_sum=var_sum+(value-mean)**2\n",
    "        var=var_sum/i\n",
    "    print('样本方差为%.2f'%var)\n",
    "function(3,6,9,23,56,78,90,2,5,6,56,89)\n",
    "print(\"\\n\")\n",
    "function(23,24,25,26,27,28,29,20,34,35,36,37,38,39)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "共有14个数值\n",
      "均值为30.07\n",
      "方差请选1，标准差请选2\n",
      "1\n",
      "样本方差为36.49\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def function(*number):\n",
    "    mean=0\n",
    "    var=0\n",
    "    var_sum=0\n",
    "    i=0\n",
    "    sum=0\n",
    "    for value in number:\n",
    "        sum=sum+value\n",
    "        i=i+1\n",
    "    mean=sum/i\n",
    "    print('共有%s个数值' %i)\n",
    "    print('均值为%.2f' %mean)\n",
    "    for value in number:\n",
    "        var_sum=var_sum+(value-mean)**2\n",
    "    var=var_sum/i\n",
    "    standard_var=var_sum**(1/2)\n",
    "    print('方差请选1，标准差请选2')\n",
    "    option=int(input())\n",
    "    if option==1:\n",
    "        print('样本方差为%.2f\\n'%var)\n",
    "    if option==2:\n",
    "        print('标准差为%.2f\\n'%standard_var)\n",
    "function(23,24,25,26,27,28,29,20,34,35,36,37,38,39)\n",
    "\n",
    "\n",
    "    \n",
    "      "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "共有14个数值\n",
      "均值为30.07\n",
      "方差请选1，标准差请选2\n",
      "1\n",
      "样本方差为36.49\n",
      "\n",
      "输出均值标准误请选1，输出最大值请选2，输出最小值请选3，选0不输出\n",
      "2\n",
      "均值的最大值为39.00\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def function(*number):\n",
    "    mean=0\n",
    "    var=0\n",
    "    var_sum=0\n",
    "    i=0\n",
    "    sum=0\n",
    "    sum_square=0\n",
    "    for value in number:\n",
    "        sum=sum+value\n",
    "        i=i+1\n",
    "    mean=sum/i\n",
    "    print('共有%s个数值' %i)\n",
    "    print('均值为%.2f' %mean)\n",
    "    for value in number:\n",
    "        var_sum=var_sum+(value-mean)**2\n",
    "    var=var_sum/i\n",
    "    standard_var=var_sum**(1/2)\n",
    "    standard_error=((sum_square/i-mean**2)*i/(i-1))/(i**(1/2))\n",
    "    print('方差请选1，标准差请选2')\n",
    "    option=int(input())\n",
    "    if option==1:\n",
    "        print('样本方差为%.2f\\n'%var)\n",
    "    if option==2:\n",
    "        print('标准差为%.2f\\n'%standard_var)\n",
    "    print('输出均值标准误请选1，输出最大值请选2，输出最小值请选3，选0不输出')\n",
    "    option=int(input())\n",
    "    if option==1:\n",
    "        print('均值的标准误为%.2f\\n'%standard_error)\n",
    "    if option==2:\n",
    "        print('均值的最大值为%.2f\\n'%max(number))\n",
    "    if option==3:\n",
    "        print('均值的最小值为%.2f\\n'%min(number))\n",
    "    if option==0:\n",
    "        print(\"Nothing\\n\")\n",
    "function(23,24,25,26,27,28,29,20,34,35,36,37,38,39)\n",
    "\n",
    "        \n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
